package com.orange.adminapi.controller.feedback;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.service.feedback.FeedbackService;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.feedback.dto.FeedbackDTO;
import com.orange.core.pojo.entity.feedback.vo.FeedbackVO;
import com.orange.core.pojo.req.feedback.FeedbackPageReq;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>ClassName:FeedbackController</p>
 * <p>Description: 商户意见反馈controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/29 11:26</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    private final FeedbackService feedbackService;

    /**
     * 商户意见反馈分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FEEDBACK_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<FeedbackVO>> page(@RequestBody PageReqDto<FeedbackPageReq> pageReqDto) {
        Page<FeedbackVO> page = feedbackService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 商户意见反馈详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FEEDBACK_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<FeedbackVO> info(@PathVariable("id")Integer id){
        return R.ok(feedbackService.info(id));
    }


    /**
     * 商户意见反馈新增
     * @param feedbackDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FEEDBACK_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated FeedbackDTO feedbackDTO){
        return BR.result(feedbackService.save(feedbackDTO));
    }

    /**
     * 商户意见反馈修改
     * @param feedbackDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FEEDBACK_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated FeedbackDTO feedbackDTO){
        return BR.result(feedbackService.update(feedbackDTO));
    }

    /**
     * 商户意见反馈批量删除
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FEEDBACK_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids")Integer[] ids){
        return BR.result(feedbackService.deleteFeedbackByIds(ids));
    }
}
